package web.sharedUI;

import ejb.dto.UserDTO;
import ejb.userManagement.AccountMgr;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class RegisterBean {
	
	@EJB
	private AccountMgr account;

	private UserDTO user;
	
	public RegisterBean() {
		user = new UserDTO();
	}

	public UserDTO getUser() {
		return user;
	}

	public void setUser(UserDTO user) {
		this.user = user;
	}
	
	/**
	 * Register a new User
	 * @return redirect to Home
	 */
	public String register() {
		boolean result = account.save(user);
		if(!result){
			SessionBean.displayError(ErrorMessage._INSERT);
			return null;
		}
		return "home?faces-redirect=true";
	}
}
